package com.example.demo.bizhan.reflect;

import org.junit.Test;

import java.lang.reflect.Method;

import static java.lang.System.out;

/**
 * @description: xxx
 * @time: 2020/10/27 11:40
 * @author: baojinlong
 **/
public class MethodDemoTest {
    @Test
    public void test02() throws Exception {
        Class<?> studentClazz = Class.forName("com.example.demo.bizhan.reflect.Student");
        Object object = studentClazz.newInstance();
        Method setSexMethod = studentClazz.getDeclaredMethod("setSex", String.class);
        setSexMethod.invoke(object, "男儿");
        out.println(object);
        Method getSex = studentClazz.getDeclaredMethod("getSex");
        out.println(getSex.invoke(object));
    }


    @Test
    public void test01() throws Exception {
        Class<?> studentClazz = Class.forName("com.example.demo.bizhan.reflect.Student");
        Method[] methods = studentClazz.getMethods();
        for (Method method : methods) {
            Class<?>[] parameterTypes = method.getParameterTypes();
            for (Class<?> parameterType : parameterTypes) {
                out.println(method.getName() + "---" + parameterType);
            }
        }
    }
}
